package org.nf.box.web.controller;

import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.nf.box.common.result.ResultVO;
import org.nf.box.domain.Comment;
import org.nf.box.domain.SubComments;
import org.nf.box.service.CommentService;
import org.nf.box.service.SubCommentService;
import org.nf.box.web.vo.CommentVO;
import org.nf.box.web.vo.SubCommentVO;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @Author lzp
 * @Date 2024-12-23
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/subComment")
public class SubCommentController {

    private final SubCommentService subCommentService; ;

    /**
     * 添加子评论
     * @return vo
     */
    @PostMapping("/add")
    public ResultVO addComment(@Param("postId")Integer postId,
                               @Param("userId")Integer userId,
                               @Param("content")String content,
                               @Param("repliedUserId")Integer repliedUserId,
                               @Param("parentId")Integer parentId) {
        SubComments subComments = new SubComments();
        subComments.setPostId(postId);
        subComments.setUserId(userId);
        subComments.setContent(content);
        subComments.setRepliedUserId(repliedUserId);
        subComments.setParentId(parentId);
        subCommentService.addComment(subComments);
        return new ResultVO<>(200,"评论成功",subComments);
    }

    /**
     * 获取子评论
     * @param parentId 父评论id
     * @return 子评论列表
     */
    @GetMapping("/get")
    public ResultVO<List<SubCommentVO>> getSubComments(@RequestParam("parentId") int parentId) {
        List<SubCommentVO> subComment = subCommentService.getSubComments(parentId);
        return new ResultVO<>(200,"",subComment);
    }
}
